package nero.yncc.com.createart.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;

import nero.yncc.com.createart.R;
import nero.yncc.com.createart.activity.ActivityChangjingDetail;
import nero.yncc.com.createart.bean.ChangjingBean;
import nero.yncc.com.createart.utils.ImageUtils;
import nero.yncc.com.createart.utils.TextUtil;

/**
 * Created by nero on 17-6-21.
 */

public class AdapterIndexChangjingList extends BaseAdapter {


    Context context;
    ArrayList<ChangjingBean> arrayList;

    public AdapterIndexChangjingList(Context context, ArrayList<ChangjingBean> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        Holder holder;
        if (view==null){
             view = LinearLayout.inflate(context, R.layout.adapter_index_changjing, null);
             holder = new Holder(view);
            view.setTag(holder);
        }else{
            holder=(Holder) view.getTag();
        }
        ChangjingBean bean = arrayList.get(i);
        //平凑所有场景字符串
        ArrayList<ChangjingBean.ChangjingInBean> arrayList_cache=( ArrayList<ChangjingBean.ChangjingInBean>)bean.getCategory_list();
        String allName="";
        for (ChangjingBean.ChangjingInBean ChangjingBean : arrayList_cache){
            allName+=ChangjingBean.getName()+"+";
        }
        allName=allName.substring(0,allName.length()-1);
        holder.tv_title.setText(TextUtil.getText(bean.getName(),"暂无名称"));
        holder.tv_content.setText(TextUtil.getText(bean.getFengge_name(),"")+"  "+
                TextUtil.getText(bean.getMianji()+"m²","")+"  "+
                TextUtil.getText(bean.getHuxing_name(),"")+"  ");
        holder.tv_allname.setText(allName);
        holder.tv_title_right.setText("共"+arrayList_cache.size()+"个场景");
        ImageUtils.BindImage(context,holder.iv_image,arrayList_cache.get(0).getPhoto(),4);
        holder.tv_content_right2.setText("省￥"+TextUtil.getText(bean.getSheng(),"省￥0"));

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(context, ActivityChangjingDetail.class);
                intent.putExtra("data",arrayList.get(i));
                context.startActivity(intent);
            }
        });
        return view;
    }

    class Holder{
        public Holder(View itemView) {
            iv_image = itemView.findViewById(R.id.iv_image);
            tv_title = itemView.findViewById(R.id.tv_title);
            tv_content = itemView.findViewById(R.id.tv_content);
            tv_allname = itemView.findViewById(R.id.tv_allname);
            tv_title_right= itemView.findViewById(R.id.tv_title_right);
            tv_content_right2= itemView.findViewById(R.id.tv_content_right2);
        }

        final ImageView iv_image;
        final TextView tv_title, tv_content,tv_allname,tv_title_right,tv_content_right2;
    }
}
